# This program demonstrates the use of radio buttons - Tutorial 10, 11, 12, 13
# Shows how spinbox is used
# Shows how listbox is used
# Shows how scale or slider is used

import sys
from tkinter import *

mainWindow = Tk()
mainWindow.geometry("450x550+200+100")
mainWindow.title("Radio Buttons, List Boxes, Slider, Spinboxes")

def clickedRadioButton():
    print("Radio Buttons Group 1: ", str(var1.get()))
    print("Radio Buttons Group 2: ", str(var2.get()))
    print("Radio Buttons Group 3: ", str(var3.get()))
    print("Radio Buttons Group 4: ", str(var4.get()))
    print("Radio Buttons Group 5: ", str(var5.get()))
    
    return

# Radio Buttons

var1 = IntVar()
var1.set(2)
radButton1 = Radiobutton(mainWindow, text="Option1", value=1, variable = var1, command=clickedRadioButton).grid(row=1, column=1)
radButton2 = Radiobutton(mainWindow, text="Option2", value=2, variable = var1, command=clickedRadioButton).grid(row=2, column=1)
radButton3 = Radiobutton(mainWindow, text="Option3", value=3, variable = var1, command=clickedRadioButton).grid(row=3, column=1)
 
var2 = IntVar()
var2.set(4)
radButton4 = Radiobutton(mainWindow, text="Option4",            value=4, variable=var2, command=clickedRadioButton).grid(row=1, column=2)
radButton5 = Radiobutton(mainWindow, text="Option5",            value=5, variable=var2, command=clickedRadioButton).grid(row=2, column=2)
radButton6 = Radiobutton(mainWindow, text="Option6 (Disabled)", value=6, variable=var2, command=clickedRadioButton, state=DISABLED).grid(row=3, column=2)

# String variable for grouping also possible
var3 = StringVar()
var3.set("9")
radButton7 = Radiobutton(mainWindow, text="Option7", value="7", variable = var3, command=clickedRadioButton).grid(row=1, column=3)
radButton8 = Radiobutton(mainWindow, text="Option8", value="8", variable = var3, command=clickedRadioButton).grid(row=2, column=3)
radButton9 = Radiobutton(mainWindow, text="Option9", value="9", variable = var3, command=clickedRadioButton).grid(row=3, column=3)

var4 = IntVar()
var4.set(10)
radButton10 = Radiobutton(mainWindow, text="Option10", value=10, variable = var4, indicatoron=False, command=clickedRadioButton).grid(row=5, column=1, padx=20)
radButton11 = Radiobutton(mainWindow, text="Option11", value=11, variable = var4, indicatoron=False, command=clickedRadioButton).grid(row=6, column=1)
radButton12 = Radiobutton(mainWindow, text="Option12", value=12, variable = var4, indicatoron=False, command=clickedRadioButton).grid(row=7, column=1)
  
# Creating large number of Radio buttons
var5 = IntVar()
var5.set(1)
i = 4       # Start onward from the 4th row
BUTTONS = [("val1", 1), ("val2", 2), ("val3", 3), ("val4", 4), ("val5", 5), ("val6", 6)]
for textOnButton, valueOfButton in BUTTONS:
    radButton = Radiobutton(mainWindow, text=textOnButton, value=valueOfButton, variable=var5, command=clickedRadioButton).grid(row=i, column=2, columnspan=2, sticky=N+E+W+S)
    i = i + 1
    
# Spinbox
label1 = Label(mainWindow, text="Spinboxes").grid(row=10, column=1)
spinbox1 = Spinbox(mainWindow, from_ = 0, to = 10, state=NORMAL).grid(row=11, column=1, sticky=N)
spinbox2 = Spinbox(mainWindow, from_ = 0, to = 10, state=DISABLED).grid(row=12, column=1, sticky=N)

# Listbox
label2= Label(mainWindow, text="Listboxes").grid(row=10, column=2, columnspan=2)
listbox1 = Listbox(mainWindow)
listbox1.insert(1, "Item1")
listbox1.insert(2, "Item2")
listbox1.insert(3, "Item3")
listbox1.insert(4, "Item4")
listbox1.grid(row=11, column=2, columnspan=2)

# Scale or Slider
scale1 = Scale(mainWindow, orient=HORIZONTAL, length=350, width=30, sliderlength=30, from_=0, to=85, tickinterval=10).grid(row=13, columnspan=3)

chkVar1 = IntVar()
chkVar1.set(0)
chkVar2 = IntVar()
chkVar2.set(1)
# Checkbox
chkBox1 = Checkbutton(mainWindow, text="Check1", state=ACTIVE, variable=chkVar1).grid(row=14, column=1)
chkBox2 = Checkbutton(mainWindow, text="Check2", state=ACTIVE, variable=chkVar2).grid(row=14, column=2)

    
mainWindow.mainloop()